package ru.spbau.krasko.phonelock.utils;

import java.util.Enumeration;
import java.util.Vector;

import net.rim.device.api.system.ApplicationDescriptor;
import ru.spbau.krasko.phonelock.dynamic.DynamicField;

public class VectorUtils {
	public static interface DynamicFieldMapper {
		void map(DynamicField df);
	}

	public static void forAllDynamicFields(Vector dynamicFields,
			DynamicFieldMapper mapper) {
		Enumeration enumeration = dynamicFields.elements();
		while (enumeration.hasMoreElements()) {
			mapper.map((DynamicField) enumeration.nextElement());
		}
	}

	public static ApplicationDescriptor[] removeDescriptor(
			ApplicationDescriptor[] array, ApplicationDescriptor element) {
		Vector v = new Vector();
		for (int i = 0; i < array.length; ++i) {
			if (!element.equals(array[i]))
				v.addElement(array[i]);
		}
		ApplicationDescriptor[] result = new ApplicationDescriptor[v.size()];
		v.copyInto(result);
		return result;
	}
}
